//
//  LiveViewController.m
//  JZMCFM
//
//  Created by Mc on 15/10/30.
//  Copyright (c) 2015年 陈卓. All rights reserved.
//

#import "LiveViewController.h"
#import "LiveFirstViewCell.h"
#import "LiveSecondViewCell.h"
#import "LiveThirdViewCell.h"
#import "LiveHelper.h"
#import "LiveModel.h"

@interface LiveViewController ()<UITableViewDelegate,UITableViewDataSource>

@property (strong, nonatomic) IBOutlet UITableView *mainTableView;

@end

@implementation LiveViewController

- (void)viewDidLoad {
    [super viewDidLoad];

    
    self.mainTableView.delegate = self;
    self.mainTableView.dataSource = self;
    
    
    //注册cell
    [self.mainTableView registerNib:[UINib nibWithNibName:@"LiveFirstViewCell" bundle:nil] forCellReuseIdentifier:@"one"];
     [self.mainTableView registerNib:[UINib nibWithNibName:@"LiveThirdViewCell" bundle:nil] forCellReuseIdentifier:@"two"];
    //    __weak LiveViewController *weakSelf = self;
    [[LiveHelper sharedInstance]downloadLiveDataFromNetWork:^{
        
        //        [weakSelf.maintableView reloadData];
        
        [self.mainTableView reloadData];
    }];

}


#pragma mark 代理方法
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
#warning 暂时先返回3个分区,后期判断
    return 2;
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{

    if (section == 0) {
        return 1;
    }else{
        return [LiveHelper sharedInstance].recommandArray.count;
    }
        
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    //判断cell
    if (indexPath.section == 0) {
        LiveFirstViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"one" forIndexPath:indexPath];
        return cell;
    }else{
        LiveThirdViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"two" forIndexPath:indexPath];
        LiveModel *model = [[LiveModel alloc]init];
        model = [LiveHelper sharedInstance].recommandArray[indexPath.row];
        
        [cell setDataFromNetWork:model];
        
        return cell;
    }
}

#pragma mark 返回分区的高度
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    if (indexPath.section == 0) {
        return  [LiveFirstViewCell heigth];
    }else{
        return 60;
    }
    
}




#pragma mark cell的点击事件
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    
}





- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
